package com.teaching.teachingsupport.controller.teachercontroller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.teachingsupport.common.pojo.dto.request.NotificationPublishRequest;
import com.teaching.teachingsupport.common.pojo.dto.response.TeachingScheduleDTO;
import com.teaching.teachingsupport.common.pojo.dto.response.TodoDTO;
import com.teaching.teachingsupport.common.pojo.dataobject.Notification;
import com.teaching.teachingsupport.common.pojo.dataobject.Todo;
import com.teaching.teachingsupport.common.utils.SecurityUtils;
import com.teaching.teachingsupport.service.service2.teacherservice.TeachingScheduleService;
import com.teaching.teachingsupport.service.service2.teacherservice.NotificationScopeService;
import com.teaching.teachingsupport.service.service2.teacherservice.TeacherTodoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/teacher")
@RequiredArgsConstructor
public class TeachingScheduleController {

    private final TeachingScheduleService teachingScheduleService;
    private final NotificationScopeService notificationScopeService;
    private final SecurityUtils securityUtils;
    private final TeacherTodoService teacherTodoService;
    
    @GetMapping("/schedule")
    public Page<TeachingScheduleDTO> getTeachingSchedule(@RequestParam(defaultValue = "1") Integer page) {
        return teachingScheduleService.getTeachingScheduleByUserId(securityUtils.getCurrentUserId(), page);
    }

    /**
     * 发布通知
     */
    @PostMapping("/notification")
    public Notification publishNotification(@RequestBody NotificationPublishRequest request) {
        return notificationScopeService.publishNotification(request);
    }

    /**
     * 删除通知
     */
    @DeleteMapping("/notification/{notificationId}")
    public void deleteNotification(@PathVariable Long notificationId) {
        notificationScopeService.deleteByNotificationId(notificationId);
    }

    /**
     * 获取可见通知列表
     */
    @GetMapping("/notification/visible")
    public List<Notification> getVisibleNotifications() {
        return notificationScopeService.getVisibleNotifications(securityUtils.getCurrentUserId());
    }

    /**
     * 获取教师待办事项列表
     * 包括：作业完成情况、教学大纲情况等
     */
    @GetMapping("/todo")
    public List<TodoDTO> getTeacherTodo() {
        return teacherTodoService.getTeacherTodoList(securityUtils.getCurrentUserId());
    }
}
